﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace BrokerBase.Lib.Product
{
    public class ProductExpander:AbstractProductExpander
    {

        private PolicyTarget pt;
        /// <summary>
        /// 保单加载完成
        /// </summary>
        /// <param name="policy"></param>
        public override void Loaded(IPolicy policy)
        {

            policy.MaxInsuranceAge = 120;

            int basicPayLength = policy.Owner.BasicPolicy.PaymentPeriodLength;

            IPaymentPeriod prepp=null;

            foreach (IPaymentPeriod pp in policy.Product.PaymentPeriods)
            {
                if (pp.Value == basicPayLength)
                {
                    policy.SelectedPaymentPeriod = pp;
                    break;
                }
                else if (pp.Value > basicPayLength)
                {
                    policy.SelectedPaymentPeriod = prepp;
                    break;
                }
                prepp = pp;
            }

            policy.Amount = policy.Owner.Policies.Sum(p => p.Amount);
            //policy.SetSettingLock("Amount", true);
            //policy.SetSettingLock("付款期限", true);

            if (policy.SelectedColRateFactors.FirstOrDefault(p => p.Key == "被保人为同一人").Value == "是")
            {
                pt = PolicyTarget.Insurant;
            }
            else
            {
                pt = PolicyTarget.Holder;
            }

        }
        /// <summary>
        /// 豁免保险针对投保人！
        /// </summary>
        public override PolicyTarget Target
        {
            get
            {
                return pt;
            }
        }

        
    }
}
